package controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description: 处理注销请求
 */
@WebServlet("/logout")
public class BlogLogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession(false);
        if(session == null) {
            // 表示用户未登录，就不需要注销
            resp.getWriter().write("当前用户未登录，无法注销!");
            return;
        }
        // 把会话中的信息删除即可
        session.removeAttribute("user");
        resp.sendRedirect("blog_login.html");
    }
}
